package com.lz.football.module.guide.view
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.events.ActivityEvent;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.GuideEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.events.NotifierEvent;
	import com.lz.football.module.activity.makestar.MakeStarView;
	import com.lz.football.module.guide.Guide;
	import com.lz.football.module.main.view.TopPanel;
	
	import flash.display.InteractiveObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import lz.controls.managers.AnimationManager;

	/**
	 *登录奖励引导 
	 * @author lake
	 * 
	 */	
	public class LoginAwardGuideView extends Guide
	{
		public function LoginAwardGuideView()
		{
			super();
		}
		/**
		 *初始化 
		 */		
		override protected function initView():void
		{
			super.initView();
			getStarFuncIcon();
		}
		/**
		 *获得七日造星按钮
		 */		
		private function getStarFuncIcon():void
		{
			GlobalDef.GameWindowContainer.addChild(bgMark);
			sceneBtn = Reflection.createInstance("com.football.main.starBtn");
			TopPanel.starBtn.visible = false;
			var appearMc :MovieClip = Reflection.createInstance("com.football.guide.AppearAtSkin");
			DisplayObjectUtil.removeAllChildren(appearMc.mc.mc);
			appearMc.mc.mc.addChild(sceneBtn);
			(sceneBtn as InteractiveObject).mouseEnabled = false;
			addDispToStage(appearMc);
			var entP :Point = TopPanel.starBtn.localToGlobal(new Point(-22,-22));
			AnimationManager.moveToThing(new Point(appearMc.x,appearMc.y),appearMc,entP,{delay:1,overwrite:0},.5);
			TweenLite.delayedCall(1.5,showStarFuncIcon);
		}
		/**
		 *显示按钮 
		 * 
		 */		
		private function showStarFuncIcon():void
		{
			TopPanel.starBtn.visible = true;
			TopPanel.resizeBtnPos();
			removeBgMark();
			//限制区域
			var rectPoint :Point = TopPanel.starBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,TopPanel.starBtn.width,TopPanel.starBtn.height);
			step();
			//指向造星按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width/3,curClickRect.y + curClickRect.height);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,180);
			sceneBtn = TopPanel.starBtn;
			arrowAngle = 180;
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_2",onLoadResComplete2);
		}
		/**
		 *界面显示
		 * @param e
		 * 
		 */		
		private function onLoadResComplete2(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_2",onLoadResComplete2);
			//限制区域
			var rectPoint :Point = MakeStarView.firstBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,MakeStarView.firstBtn.width,MakeStarView.firstBtn.height);
			step();
			//指向领取按钮
			var arrrowPoint :Point = new Point(curClickRect.x - 10,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn = MakeStarView.firstBtn;
			arrowAngle = -90;
			//事件
			GlobalDef.GameStage.addEventListener(ActivityEvent.ACTIVITY_MAKESTAR_AWARD,onAwardHandler);
		}
		/**
		 *领取 
		 * @param event
		 */		
		protected function onAwardHandler(event:ActivityEvent):void
		{
			GlobalDef.GameStage.removeEventListener(ActivityEvent.ACTIVITY_MAKESTAR_AWARD,onAwardHandler);
			//提交引导
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE,{step:2}));
			//限制区域
			var rectPoint :Point = MakeStarView.closeBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,MakeStarView.closeBtn.width,MakeStarView.closeBtn.height);
			step();
			//指向关闭按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width + 10,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn = MakeStarView.closeBtn;
			arrowAngle = 90;
			//事件
			GlobalDef.GameStage.addEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
		}
		/**
		 *  关闭
		 * @param e
		 * 
		 */		
		private function onRemoveModuleHandler(e :Event):void
		{
			GlobalDef.GameStage.removeEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
			removeArrowMc();
			//@lake 2013-11-15
			//第2步刷新
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE+"_refresh",{step:2}));
		}
		/**
		 *执行 
		 * 
		 */		
		override public function process():void
		{
			initView();
		}
		/**
		 *清理 
		 * 
		 */		
		override public function clear():void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_2",onLoadResComplete2);
			GlobalDef.GameStage.removeEventListener(ActivityEvent.ACTIVITY_MAKESTAR_AWARD,onAwardHandler);
			GlobalDef.GameStage.removeEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
			super.clear();
		}
	}
}